import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutterlib/common/localization/quhui_string_base.dart';
import 'package:flutterlib/common/localization/quhui_string_en.dart';
import 'package:flutterlib/common/localization/quhui_string_zh.dart';

///自定义多语言实现
class QuhuiLocalizations {
  final Locale locale;

  QuhuiLocalizations(this.locale);

  ///根据不同 locale.languageCode 加载不同语言对应
  ///QuhuiStringEn和QuhuiStringZh都继承了QuhuiStringBase
  static Map<String, QuhuiStringBase> _localizedValues = {
    'en': new QuhuiStringEn(),
    'zh': new QuhuiStringZh(),
  };

  QuhuiStringBase get currentLocalized {
    if (_localizedValues.containsKey(locale.languageCode)) {
      return _localizedValues[locale.languageCode];
    }
    return _localizedValues["en"];
  }

  ///通过 Localizations 加载当前的 QuhuiLocalizations
  ///获取对应的 QuhuiStringBase
  static QuhuiLocalizations of(BuildContext context) {
    return Localizations.of(context, QuhuiLocalizations);
  }

  ///通过 Localizations 加载当前的 QuhuiLocalizations
  ///获取对应的 QuhuiStringBase
  static QuhuiStringBase i18n(BuildContext context) {
    return (Localizations.of(context, QuhuiLocalizations) as QuhuiLocalizations)
        .currentLocalized;
  }
}
